package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.NewsMapper;
import com.aaa.hospital.pojo.domain.News;
import com.aaa.hospital.pojo.query.NewsQuery;
import com.aaa.hospital.pojo.vo.NewsVO;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @program:qy888
 * @description:www
 * @author:LJW
 * @version: 1.0
 * @create:2022-2-16 09:11
 */
@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public AjaxResult queryNews(NewsQuery newsQuery) {

        List<News> news = newsMapper.queryNews(newsQuery);

        Long aLong = newsMapper.queryNewsTotal(newsQuery);

        HashMap<Object,Object> objectObjectHashMap = new HashMap<>();

        objectObjectHashMap.put("currentData",news);
        objectObjectHashMap.put("totalCount",aLong);

        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult addNews(NewsVO newsVO) {
        int i = newsMapper.addNews(newsVO);
        if (i<0){
            return AjaxResult.fail();
        }
        return AjaxResult.success();
    }

    @Override
    public AjaxResult deletenews(Integer id) {
        int i =newsMapper.deletenews(id);
        if (i>1){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult get(Integer id) {
        News n=newsMapper.seeByID(id);
        return AjaxResult.success(n);
    }


    @Override
    public AjaxResult index() {
        List<News> news=newsMapper.index();
        return AjaxResult.success(news);
    }

    @Override
    public AjaxResult show(Integer id) {
        News n=newsMapper.showByID(id);
        return AjaxResult.success(n);
    }

}
